<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>对象运算符的扩展</title>
  <script type="text/javascript">

    let cat={name:"小花猫",age:2};
    // let cat2=cat;  //浅拷贝
    // cat2.name="大花猫"
    //
    // console.log("cat=",cat) //name=大花猫
    // console.log("cat2=",cat2) //name=大花猫

    //浅拷贝:复制该引用的地址，都指向同一个对象，修改会影响原对象
    //深拷贝:复制该对象的值并创建新对象修改不会影响原对象

    //深拷贝
    let cat2={...cat}
    cat2.name="大花猫"
    console.log("cat->",cat)//name=小花猫
    console.log("cat2->",cat2)//name=大花猫

    //合并对象 (深拷贝)
    let monster={name:"白骨精",age:100}
    let car={brand:"奔驰",price:800000}
    let monster_car={...monster,...car}
    monster_car.name="狐狸精"
    console.log("monster->",monster) //name=白骨精
    console.log("monster_car->",monster_car) //name=狐狸精 //说明是深拷贝
  </script>
</head>
<body>

</body>
</html>